﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _17_LetterCombinations
{
    class Program
    {
        //static string[][] mapping = {  new string[] { "0" },
        //                        new string[] { "1" },
        //                        new string[] { "a","b","c" },
        //                        new string[] { "d","e","f" },
        //                        new string[] { "g","h","i" },
        //                        new string[] { "j","k","l" },
        //                        new string[] { "m","n","o" },
        //                        new string[] { "p","q","r", "s" },
        //                        new string[] { "t","u","v" },
        //                        new string[] { "w","x","y","z" },
        //                    };

        static Dictionary<char, List<string>> mapping = new Dictionary<char, List<string>>(){
        {'0', new List<string>()}, {'1', new List<string>()}, {'2', new List<string>(){"a","b","c"}},
        {'3', new List<string>(){"d","e","f"}}, {'4', new List<string>(){"g","h","i"}}, {'5', new List<string>(){"j","k","l"}},
        {'6', new List<string>(){"m","n","o"}}, {'7', new List<string>(){"p","q","r","s"}}, {'8', new List<string>(){"t","u","v"}},
        {'9', new List<string>(){"w","x","y","z"}}};

        static void Main(string[] args)
        {
            string str = "23";

            IList<string> result = LetterCombinations(str);

            foreach (string s in result)
            {
                Console.WriteLine(s);
            }

            Console.ReadLine();
        }

        private static IList<string> LetterCombinations(string digits)
        {
            List<string> result = new List<string>();

            GetAllCombinations(digits, result, 0, string.Empty);

            return result;
        }

        private static void GetAllCombinations(string digits, List<string> res, int curr, string current)
        {
            if (curr >= digits.Length)
            {
                if (current.Length > 0)
                    res.Add(current);
                return;
            }

            foreach (var s in mapping[digits[curr]])
                GetAllCombinations(digits, res, curr + 1, current + s);
        }
    }
}